import { Entity, PrimaryGeneratedColumn, ManyToOne, CreateDateColumn, JoinColumn } from 'typeorm';
import { Text } from './text.entity';
import { Tag } from '../../tags/entities/tag.entity';

@Entity('text_tags')
export class TextTag {
  @PrimaryGeneratedColumn()
  id: number;

  @ManyToOne(() => Text, text => text.textTags, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'text_id' })
  text: Text;

  @ManyToOne(() => Tag, tag => tag.textTags, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'tag_id' })
  tag: Tag;

  @CreateDateColumn({ 
    name: 'createdAt',
    type: 'timestamp',
    precision: 0,
    default: () => 'CURRENT_TIMESTAMP'
  })
  createdAt: Date;
}